
#from django.forms.formsets import formset_factory
#from django.forms.models import inlineformset_factory
from django.forms import ModelForm
from django import forms
from django.contrib.auth.models import User
from homesite.bugs.models import Project
from homesite.bugs.models import Task
from homesite.bugs.models import History
from homesite.bugs import fields



BUG_RESOLUTION_CHOICES = (
    ('Fixed', 'Fixed'),
    ('Canceled', 'Canceled'),
    ('Invalid', 'Invalid'),
    ('Same as', 'Same as'),
)



FEATURE_RESOLUTION_CHOICES = (
    ('Implemented', 'Implemented'),
    ('Denided', 'Denided'),
    ('Invalid', 'Invalid'),
    ('Same as', 'Same as'),
)



class TaskForm(ModelForm): 
    project =  forms.ModelChoiceField(Project.objects.all(), widget=forms.HiddenInput)
    kind =  forms.CharField(widget=forms.HiddenInput)
    status =  forms.CharField(widget=forms.HiddenInput)
    summary = forms.CharField(widget=forms.TextInput(attrs={'size':'80'}))
    description = forms.CharField(widget=forms.Textarea(attrs={'cols':'61','rows':'5'}))
    reporter = forms.ModelChoiceField(User.objects.all(), widget=forms.HiddenInput)
    owner = forms.ModelChoiceField(User.objects.all(), empty_label=None) 
    subscribers =  forms.MultipleChoiceField(choices=[ (str(u.id), str(u.username)) for u in User.objects.all() ], widget=forms.CheckboxSelectMultiple, required=False)
 
    class Meta:
        model = Task#CheckboxSelectMultiple   (str(u.id), str(u.username)) for u in User.objects.all()  



class HistoryForm(TaskForm):
    comment = forms.CharField(widget=forms.Textarea(attrs={'cols':'61','rows':'5'}), required=False)
    attachment = forms.FileField(required=False)



class TaskBugHistoryForm(HistoryForm):                                
    resolution  = forms.ChoiceField(required=False, choices=BUG_RESOLUTION_CHOICES)



class TaskFeatureHistoryForm(HistoryForm):
    resolution = forms.ChoiceField(required=False, choices=FEATURE_RESOLUTION_CHOICES)

    
    

